<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
    >
      <el-form-item label="签名时间">
        <el-date-picker
          v-model="daterangeSignTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="签名人姓名" label-width="90px" prop="signUserName">
        <el-input
          v-model="queryParams.signUserName"
          placeholder="请输入签名人姓名"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Sop填报流水编号" label-width="130px" prop="sopProdCode">
        <el-input
          v-model="queryParams.sopProdCode"
          placeholder="请输入Sop填报流水编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['signRecord:signRecord:remove']"
          >删除</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['signRecord:signRecord:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="signRecordList"
      border
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column
        label="签名时间"
        align="center"
        prop="signTime"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.signTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="签名人姓名" align="center" prop="signUserName" />
      <el-table-column
        label="Sop填报流水编号"
        align="center"
        prop="sopProdCode"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            link
            type="primary"
            icon="View"
            @click="handleView(scope.row, scope.index)"
            v-hasPermi="['signRecord:signRecord:query']"
            >详细</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改签名记录对话框 -->
    <el-dialog title="记录详情" :close-on-click-modal="false" v-model="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="签名时间" prop="signTime">
          {{ form.signTime }}
        </el-form-item>
        <el-form-item label="签名人姓名" prop="signUserName">
          {{ form.signUserName }}
        </el-form-item>
        <el-form-item label="Sop填报流水编号" prop="sopProdCode">
          {{ form.sopProdCode }}
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          {{ form.remark }}
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSignRecord,
  getSignRecord,
  updateSignRecord,
  addSignRecord,
  delSignRecord,
} from "@/api/system/signRecord";

export default {
  name: "SignRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 签名记录表格数据
      signRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      daterangeSignTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        signTime: null,
        signUserName: null,
        sopProdCode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        signTime: [
          { required: true, message: "签名时间不能为空", trigger: "blur" },
        ],
        signUserName: [
          { required: true, message: "签名人姓名不能为空", trigger: "blur" },
        ],
        signUserId: [
          { required: true, message: "签名人id不能为空", trigger: "blur" },
        ],
        sopProdCode: [
          {
            required: true,
            message: "Sop填报流水编号不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询签名记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeSignTime && "" != this.daterangeSignTime) {
        this.queryParams.params["beginSignTime"] = this.daterangeSignTime[0];
        this.queryParams.params["endSignTime"] = this.daterangeSignTime[1];
      }
      listSignRecord(this.queryParams).then((response) => {
        this.signRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        signTime: null,
        signUserName: null,
        signUserId: null,
        sopProdCode: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeSignTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加签名记录";
    },
    /** 修改按钮操作 */
    handleView(row) {
      this.reset();
      const id = row.id || this.ids;
      getSignRecord(id).then((response) => {
        this.form = response.data;
        this.open = true;
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除签名记录编号为"' + ids + '"的数据项？')
        .then(function () {
          return delSignRecord(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "signRecord/signRecord/export",
        {
          ...this.queryParams,
        },
        `signRecord_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
